let api = [];
api.push({
    alias: 'api',
    order: '1',
    desc: 'WebRtc信令模块',
    link: 'webrtc信令模块',
    list: []
})
api[0].list.push({
    order: '1',
    methodId: 'a775aaf35a3397b509daadd99e9100af',
    desc: 'webrtc sdp协议交互',
});
api[0].list.push({
    order: '2',
    methodId: '0d64ed9f4e96c5c983a435ed7c4cb517',
    desc: '推流sdp交互',
});
api[0].list.push({
    order: '3',
    methodId: 'edba23cc17085d17f435cee8d6ffca12',
    desc: '拉流sdp交互',
});
api[0].list.push({
    order: '4',
    methodId: '98dd330e53007f8954cfadc766c7bab3',
    desc: '删除webrtc  要显式终止会话，WHEP 播放器必须对初始HTTP POST的Location头字段中返回的资源URL执行HTTP DELETE请求。收到HTTP DELETE请求后，WHEP资源将被删除，并在媒体服务器上释放资源',
});
api.push({
    alias: 'TranscodeController',
    order: '2',
    desc: '转码',
    link: '转码',
    list: []
})
api[1].list.push({
    order: '1',
    methodId: '683e18d986bcef7a62493aa460a2fa6a',
    desc: '转码 默认H265转H264 支持分辨率调整 暂时只支持视频转码，音频因为各种封装格式对编码格式、音频参数等转换规则复杂暂时不支持',
});
api.push({
    alias: 'SnapController',
    order: '3',
    desc: '截图接口',
    link: '截图接口',
    list: []
})
api[2].list.push({
    order: '1',
    methodId: '7c95fa3a429d7ff145fa430df9d0f8e5',
    desc: '获取截图',
});
api.push({
    alias: 'ApiController',
    order: '4',
    desc: '流媒体Api',
    link: '流媒体api',
    list: []
})
api[3].list.push({
    order: '1',
    methodId: 'd9eacd8e14748a6129849b54b0b1b142',
    desc: '添加rtmp/rtsp拉流代理',
});
api[3].list.push({
    order: '2',
    methodId: '8ad7d6a9368deec6cfd0426d333f4c8d',
    desc: '关闭拉流代理',
});
api[3].list.push({
    order: '3',
    methodId: '060e5726e17ca50a218ee079a5623216',
    desc: '添加rtmp/rtsp推流代理',
});
api[3].list.push({
    order: '4',
    methodId: '7c771174adf9fb3901680d3086ef4f29',
    desc: '删除rtmp/rtsp推流代理',
});
api[3].list.push({
    order: '5',
    methodId: 'bb8cd6f820877b86a4aa2783b154d97c',
    desc: '关闭流',
});
api[3].list.push({
    order: '6',
    methodId: 'a8e6807cfbf1e362884ccee32e31d47e',
    desc: '关闭流(批量关)',
});
api[3].list.push({
    order: '7',
    methodId: 'cb490cd9458f63eb655f8823b7781aa6',
    desc: '获取流列表',
});
api[3].list.push({
    order: '8',
    methodId: '30e999ede44f252bc8a4934c712c9d5c',
    desc: '获取流信息',
});
api[3].list.push({
    order: '9',
    methodId: '2fe94fdb67f7f5e2a30ab1bc9eea5871',
    desc: '流是否在线',
});
api[3].list.push({
    order: '10',
    methodId: '902c61be35be8f9b57a7505900947ac7',
    desc: '开始录像',
});
api[3].list.push({
    order: '11',
    methodId: '576abb5edb7c4dde0dd0278c384c492b',
    desc: '停止录像',
});
api[3].list.push({
    order: '12',
    methodId: 'a12e257c35736da5153e5db5d5323f6d',
    desc: '是否录像',
});
api[3].list.push({
    order: '13',
    methodId: 'a0484e224f8e38ff7bd252cf03877ecb',
    desc: '获取内存资源信息',
});
api[3].list.push({
    order: '14',
    methodId: '3f37be3a2f369575e0d0ab67770aec98',
    desc: '获取服务器配置',
});
api[3].list.push({
    order: '15',
    methodId: '310e54f4d4c17edb539c007b1314677e',
    desc: '重启流媒体服务',
});
api[3].list.push({
    order: '16',
    methodId: '615ed40028c34a806f45a7072ea2e30c',
    desc: '设置服务器配置',
});
api[3].list.push({
    order: '17',
    methodId: 'db3f953c5d773b922a5492e4fe6de9be',
    desc: '开启rtp服务',
});
api[3].list.push({
    order: '18',
    methodId: '58909213ed8a824f1e07380a8163ce38',
    desc: '关闭rtp服务',
});
api[3].list.push({
    order: '19',
    methodId: '8bea9df3e3e43e4b78fc770481c033fa',
    desc: '获取所有RTP服务器',
});
api.push({
    alias: 'StackController',
    order: '5',
    desc: '拼接屏控制类',
    link: '拼接屏控制类',
    list: []
})
api[4].list.push({
    order: '1',
    methodId: '0dc8cbfe38639e2189d0e886fbd27dba',
    desc: '开启拼接屏',
});
api[4].list.push({
    order: '2',
    methodId: '9d667b042adc3e33bef86ee899d00550',
    desc: '重新设置拼接屏',
});
api[4].list.push({
    order: '3',
    methodId: '34018296fa44c3c3fd651a1494967b3b',
    desc: '关闭拼接屏',
});
api.push({
    alias: 'TestController',
    order: '6',
    desc: '测试接口',
    link: '测试接口',
    list: []
})
api[5].list.push({
    order: '1',
    methodId: '17ef9c0b00ea7c6b87e0b8ebeed12a23',
    desc: '生成一路测试视频流',
});
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
    const theEvent = e;
    const code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code === 13) {
        const search = document.getElementById('search');
        const searchValue = search.value;
        let searchArr = [];
        for (let i = 0; i < api.length; i++) {
            let apiData = api[i];
            const desc = apiData.desc;
            if (desc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                searchArr.push({
                    order: apiData.order,
                    desc: apiData.desc,
                    link: apiData.link,
                    alias: apiData.alias,
                    list: apiData.list
                });
            } else {
                let methodList = apiData.list || [];
                let methodListTemp = [];
                for (let j = 0; j < methodList.length; j++) {
                    const methodData = methodList[j];
                    const methodDesc = methodData.desc;
                    if (methodDesc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                        methodListTemp.push(methodData);
                        break;
                    }
                }
                if (methodListTemp.length > 0) {
                    const data = {
                        order: apiData.order,
                        desc: apiData.desc,
                        alias: apiData.alias,
                        link: apiData.link,
                        list: methodListTemp
                    };
                    searchArr.push(data);
                }
            }
        }
        let html;
        if (searchValue === '') {
            const liClass = "";
            const display = "display: none";
            html = buildAccordion(api,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        } else {
            const liClass = "open";
            const display = "display: block";
            html = buildAccordion(searchArr,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        }
        const Accordion = function (el, multiple) {
            this.el = el || {};
            this.multiple = multiple || false;
            const links = this.el.find('.dd');
            links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
        };
        Accordion.prototype.dropdown = function (e) {
            const $el = e.data.el;
            let $this = $(this), $next = $this.next();
            $next.slideToggle();
            $this.parent().toggleClass('open');
            if (!e.data.multiple) {
                $el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
            }
        };
        new Accordion($('#accordion'), false);
    }
}

function buildAccordion(apiData, liClass, display) {
    let html = "";
    if (apiData.length > 0) {
         for (let j = 0; j < apiData.length; j++) {
            html += '<li class="'+liClass+'">';
            html += '<a class="dd" href="#' + apiData[j].alias + '">' + apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
            html += '<ul class="sectlevel2" style="'+display+'">';
            let doc = apiData[j].list;
            for (let m = 0; m < doc.length; m++) {
                html += '<li><a href="#' + doc[m].methodId + '">' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + doc[m].desc + '</a> </li>';
            }
            html += '</ul>';
            html += '</li>';
        }
    }
    return html;
}